package com.test.springai.config;

import java.util.List;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 8/20/25 8:42 AM
 * @modifiedBy:
 * @version: 1.0
 */
@Configuration
public class RagConfig {
  @Bean
  ChatClient chatClient(ChatClient.Builder builder) {
    return builder.defaultSystem("你将作为一名Java开发语言的专家，对于用户的使用需求作出解答").build();
  }

  @Bean
  VectorStore vectorStore(EmbeddingModel embeddingModel) {
    SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(embeddingModel).build();

    // 生成一个说明的文档
    List<Document> documents =
        List.of(
            new Document(
                """
                产品说明：
                名称：Java开发语言
                产品描述：Java是一种面向对象的开发语言
                特性：
                1.封装
                2.继承
                3.多态
                """));
    // 进行向量化存储
    simpleVectorStore.add(documents);
    return simpleVectorStore;
  }
}
